<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
</head>
<body>
  <div id="app">
   <h4>说明：这个版本是针对保留两位小数的浮点数进行过滤格式化的</h4>
   <input type="number" v-model="num" />
   <p>{{num|NumFormat}}</p>
  </div>
 </body>
 <script>
  Vue.filter('NumFormat', function(value) {
   if(!value) return '0';
   var value2Array = value.split(".");
   var intPart = value2Array[0].toString(); //获取整数部分
   var intPartFormat = intPart.toString().replace(/(\d)(?=(\d{3})+$)/g, '$1,'); //将整数部分逢三一断
   var floatPart = value2Array[1]; //拿到小数部分
   if(floatPart != undefined && floatPart != "undefined")
	return intPartFormat  + "." +  floatPart;
   else
	return intPartFormat;	
  })
  var app = new Vue({
   el: "#app",
   data: {
    num: 0
   },
  })
 </script>
</html>